package personal.vivian.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.support.RequestContextUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;

@Controller
@RequestMapping(value = "/checklanguage" )
@Slf4j
public class LanguageControlle {
    @RequestMapping(value = "/CN")
    public String check(HttpServletRequest request, HttpServletResponse response, @PathVariable String language){
        Locale locale = request.getLocale();
        //log.warn(locale.toString());
        LocaleResolver localeResolver = RequestContextUtils.getLocaleResolver(request);
        if(language==null){
            return "index";
        }else{
            if("CN".equals(language)){
                localeResolver.setLocale(request,response,Locale.CHINA);
            }else if("US".equals(language)){
                localeResolver.setLocale(request,response,Locale.US);
            }
        }
        return "index";

    }
}
